package servlet;

import com.alibaba.fastjson.JSON;
import service.BrandService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.BufferedReader;
import java.io.IOException;
//批量删除
@WebServlet(name = "DeleteAllServlet", value = "/deleteByIds")
public class DeleteAllServlet extends HttpServlet {
    BrandService service = new BrandService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 接收id
        BufferedReader id = request.getReader();
        String params = id.readLine();
        int[] ids = JSON.parseObject(params,int[].class);
        //2. 调用service 完成修改
        service.deleteByIds(ids);
        //3. 转发到查询所有
        request.getRequestDispatcher("/SelectAll").forward(request,response);
    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}